package com.esoon.logFile;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Date;

/**
 * @author Jack
 * @version 1.0.0
 * @PackageName com.esoon.logFile
 * @ClassName InputLogFileController
 * @Description TODO
 * @createTime 2021年01月25日 18:37:00
 */
@RestController
@RequestMapping("/if")
@CrossOrigin
public class InputLogFileController {
    private final Logger logger = LoggerFactory.getLogger(InputLogFileController.class);
    @GetMapping("/getTxt")
    public String getSomeTxt(){
        logger.info("我们来过，我们见证，我们征服。");
        return "浏览器获取成功";
    }

    @Scheduled(cron = "0/1 * * * * ? ")
    public  void inputLogFile(){
        LocalDateTime now = LocalDateTime.now();
        DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        String format = dateTimeFormatter.format(now);
        logger.info("every second generate one message,now time is [{}]",format);
    }
}
